package com.bocaizp.operation.service.impl;

import com.bocaizp.operation.mapper.CompanyMapper;
import com.bocaizp.operation.service.CompanySerivce;
import com.bocaizp.pojo.DTO.CompanyDTO;
import com.bocaizp.pojo.DTO.JobDataDTO;
import com.bocaizp.pojo.VO.CompanyShowVO;
import com.bocaizp.pojo.VO.IndustryVO;
import com.bocaizp.pojo.entity.Company;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : huang jie
 * Date : 2024/5/4 22:10
 **/
@Service
public class CompanySerivceImpl implements CompanySerivce {

	@Autowired
	private CompanyMapper companyMapper;

	/**
	 * 获取公司行业
	 * @return
	 */
	public List<IndustryVO> getindustry() {
		return companyMapper.getindustry();
	}

	/**
	 * 获取公司列表
	 * @param companyDTO
	 * @return
	 */
	public List<CompanyShowVO> getcompany(CompanyDTO companyDTO) {
		List<CompanyShowVO> company = companyMapper.getcompany(companyDTO);
		List<CompanyShowVO> companyShowVOS1 = new ArrayList<>();

		for (CompanyShowVO companyShowVO : company){
			CompanyShowVO companyShowVO1 = new CompanyShowVO();
			BeanUtils.copyProperties(companyShowVO, companyShowVO1);
			JobDataDTO jobDataDTO = companyMapper.getHotJob(companyShowVO.getName());
			if(jobDataDTO != null){
				String salary = backSalary(jobDataDTO.getSalaryBottom(), jobDataDTO.getSalaryTop(), jobDataDTO.getSalaryMonth());
				companyShowVO1.setJobSalary(salary);
				companyShowVO1.setHotJob(jobDataDTO.getJob());
			}else {
				companyShowVO1.setJobSalary(null);
				companyShowVO1.setHotJob(null);
			}
			companyShowVOS1.add(companyShowVO1);
		}
		return companyShowVOS1;
	}


	public String backSalary(int salary_bottom, int salary_top, int salary_month){
		String s_bottom = salary_bottom / 1000 + "";
		String s_top = salary_top / 1000 + "";
		String s_month = "";
		if(salary_month != 12){
			s_month = "·" + salary_month + "薪";
		}
		return s_bottom + "-" +s_top + "K" + s_month;
	}
}
